package com.company.huisuo.biz.fragment

import androidx.recyclerview.widget.LinearLayoutManager
import com.company.huisuo.R
import com.company.huisuo.base.BaseFragment
import com.company.huisuo.biz.activity.ArtistInfoActivity
import com.company.huisuo.biz.adapter.ArtistRankListAdapter
import com.company.huisuo.biz.bean.ArtistBean
import com.company.huisuo.databinding.FragmentArtistRankBinding
import com.company.huisuo.ext.dp2px
import com.company.huisuo.ext.loadCircleImg
import com.company.huisuo.ext.loadImg
import com.company.huisuo.widget.DashedItemDecoration

/**
 * 艺人榜单Fragment
 */
class ArtistRankFragment : BaseFragment<FragmentArtistRankBinding>() {

    private val mListAdapter by lazy {
        ArtistRankListAdapter()
    }

    companion object {
        fun newInstance(): ArtistRankFragment {
            return ArtistRankFragment()
        }
    }

    override fun initView() {
        mBinding?.apply {
            rcvArtistList.apply {
                layoutManager = LinearLayoutManager(requireContext())
                adapter = mListAdapter
                addItemDecoration(
                    DashedItemDecoration(
                        requireActivity(),
                        startPadding = 48.dp2px().toFloat(),
                        endPadding = 40.dp2px().toFloat()
                    )
                )
            }

            ivArtistCenter.loadCircleImg(ArtistBean.ARTIST_1.avatar)
            tvTitleCenter.text = ArtistBean.ARTIST_1.name
            ivArtistCenter.setOnClickListener {
                ArtistInfoActivity.start(requireActivity(), ArtistBean.ARTIST_1)
            }

            ivArtistLeft.loadCircleImg(ArtistBean.ARTIST_2.avatar)
            tvTitleLeft.text = ArtistBean.ARTIST_2.name
            ivArtistLeft.setOnClickListener {
                ArtistInfoActivity.start(requireActivity(), ArtistBean.ARTIST_2)
            }

            ivArtistRight.loadCircleImg(ArtistBean.ARTIST_3.avatar)
            tvTitleRight.text = ArtistBean.ARTIST_3.name
            ivArtistRight.setOnClickListener {
                ArtistInfoActivity.start(requireActivity(), ArtistBean.ARTIST_3)
            }
        }
    }

    override fun initData() {
        // 设置底部列表
        mListAdapter.submitList(mockListData())
    }

    /**
     * 模拟列表数据
     */
    private fun mockListData(): ArrayList<ArtistBean> {
        val list = ArrayList<ArtistBean>()
        list.add(ArtistBean.ARTIST_4)
        list.add(ArtistBean.ARTIST_5)
        list.add(ArtistBean.ARTIST_6)
        list.add(ArtistBean.ARTIST_7)
        list.add(ArtistBean.ARTIST_8)
        return list
    }
}
